package faktorI;

import java.io.*;
public class Scaner extends Tokenstream {
		private StreamTokenizer strtok;
		public Scaner(String s) {
			StringReader r = new StringReader(s);
			strtok = new StreamTokenizer(r);
			setup();
			next();
		}
		private void setup() {
			strtok.resetSyntax();
			strtok.parseNumbers();
			strtok.wordChars('a', 'z');
			strtok.wordChars('A', 'Z');
			strtok.wordChars('0', '9');
			strtok.wordChars('_', '_');
			strtok.whitespaceChars(' ', ' ');
			strtok.whitespaceChars('\t', '\t');
			strtok.whitespaceChars('\n', '\n');
			strtok.whitespaceChars('\r', '\r');
			strtok.commentChar('/');
		}
		public void next(){
			if (tok != EOF)
				try {
					tok = strtok.nextToken();
					switch (tok) {
					case StreamTokenizer.TT_EOF:
						sval = "<EOF>";
						tok = EOF;
						break;
					case StreamTokenizer.TT_NUMBER:
						nval = strtok.nval;
						tok = DOUBLE;
						break;
					case StreamTokenizer.TT_WORD:
						if(strtok.sval.equals("I")){
							sval = strtok.sval;
							tok = I;
						}
						else if(strtok.sval.equals("ILI")){
							sval = strtok.sval;
							tok = ILI;
						}
						else if(strtok.sval.equals("AKO")){
							sval = strtok.sval;
							tok = AKO;
						}
						else if(strtok.sval.equals("ONDA")){
							sval = strtok.sval;
							tok = ONDA;
						}
						else{
							sval = strtok.sval;
							tok = WORD;
						}
						break;
					case '(':
						sval = "(";
						tok = '(';
						break;
					case ')':
						sval = ")";
						tok = ')';
						break;
					case '-':
						sval = "-";
						tok = '-';
						break;
					default:
						throw new Greska("Illegal token " + this);
					}
				} catch (IOException e) { throw new Greska(e.getMessage()); }
			}
		public String toString() {
			switch (tok) {
			case StreamTokenizer.TT_EOF: case EOF:
				return "<EOF>";
			case StreamTokenizer.TT_NUMBER: case DOUBLE:
				return "" + strtok.nval;
			case StreamTokenizer.TT_WORD:
				return "" + strtok.sval;
			default:
				return "" + (char)tok;
			}
		}
}